const {
  http
} = require("../../../../utils/apiutils")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    pageNo: 1,
    total: 0,
    status: 4,
    rzInfo: {},
    rzshow: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    if (options.type) {
      if (options.type == 1) {
        this.setData({
          active: 1
        })
      } else if (options.type == 2) {
        this.setData({
          active: 2
        })
      } else if (options.type == 3) {
        this.setData({
          active: 0
        })
      } else if (options.type == 4) {
        this.setData({
          active: 3
        })
      }
    }

  },
  onChange: function (event) {
    let a = event.detail.name;
    console.log("----------选择的状态---", a);
    var status, pageNo = 1,
      total = 0;
    if (a == 0) {
      status = 4;
    } else if (a == 1) {
      status = 1;
    } else if (a == 2) {
      status = 3;
    } else if (a == 3) {
      status = 6;
    } else if (a == 4) {
      status = "";
    }
    this.setData({
      status,
      pageNo,
      total
    })
    this.getDataList();
  },
  onclickJF: function (e) {
    let item = e.currentTarget.dataset.item;
    console.log("---------", item);
    wx.navigateTo({
      url: '/pages/home/pages/bond/bond?id=' + item.id,
    })

  },

  onclickJob:function(e)
  {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pages/home/pages/work/work?id=' + item.jobId,
    })
  },
  onclickColse: function (e) {
    let item = e.currentTarget.dataset.item;
    console.log("-----------", item);
    var that = this;
    wx.showModal({
      title: "提示",
      content: "您确定要取消已报名的岗位吗？",
      success: function (res) {
        if (res.confirm) {
          wx.showLoading({
            title: '加载中...',
          })
          http.registrationD(item.id,
            function (res) {
              wx.hideLoading()
              if (res.code == 0) {
                wx.showToast({
                  title: "取消成功",
                  icon: "none",
                })
                that.getDataList()
              } else {
                wx.showToast({
                  title: res.message,
                  icon: "none",
                })
              }
            },
            function (err) {
              wx.hideLoading()
            })
        }
      }
    })



  },
  onclickGZDk: function (e) {
    let item = e.currentTarget.dataset.item;
    // console.log("-------到岗打卡-----",item);
    // this.clockIn(item.id);
    let data = {
      id: item.id,
      name: item.jobName,
      workplace: item.workplace,
      type: 2,
      jobId: item.jobId,
    }
    wx.navigateTo({
      url: '/pages/clockin/clockin?data=' + encodeURIComponent(JSON.stringify(data)),
    })

  },

  onclickDGDK: function (e) {
    let item = e.currentTarget.dataset.item;
    // console.log("-------到岗打卡-----",item);
    // this.clockIn(item.id);
    var str = item.interviewDate||'';
    str = str.substring(0, 19);
    str = str.replace(/-/g, '/');
    let date = new Date(str);
    var interviewDate = date.getFullYear().toString() + "-" + (date.getMonth() + 1).toString() + "-" + date.getDate().toString(); // 年
    let data = {
      id: item.id,
      name: item.jobName,
      workplace: item.workplace,
      type: 1,
      jobId: item.jobId,
      interviewDate: interviewDate,
    }
    wx.navigateTo({
      url: '/pages/clockin/clockin?data=' + encodeURIComponent(JSON.stringify(data)),
    })

  },
  onclicklyqx (e) {
    let item = e.currentTarget.dataset.item;
    console.log("-----------", item);
    let that = this;
    wx.showModal({
      title: "提示",
      content: "您确定要取消已报名的岗位吗？",
      success: function (res) {
        if (res.confirm) {
          wx.showLoading({
            title: '加载中...',
          })
          http.registrationD(item.id,
            function (res) {
              wx.hideLoading()
              that.getDataList();
              if (res.code == 0) {
                wx.showToast({
                  title: "取消成功",
                  icon: "none",
                })
              } else {
                wx.showToast({
                  title: res.message,
                  icon: "none",
                })
              }
            },
            function (err) {
              wx.hideLoading()
            })

        }


      }
    })


  },
  onClose: function () {
    this.setData({
      rzshow: false,
    })
  },
  onclickCall: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.rzInfo.contactPhone,
    })
  },
  onclicklxrz: function (e) {
    let item = e.currentTarget.dataset.item;
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.entryInfo(item.jobId,
      function (res) {
        wx.hideLoading()
        console.log("------报名岗位列表---", res);
        if (res.code == 0) {
          that.setData({
            rzInfo: res.data,
            rzshow: true,
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },
  onclickFW: function (e) {

    let item = e.currentTarget.dataset.item;
    let data = {
      id: item.id,
      name: item.jobName,
      workplace: item.workplace,
      type: 3,
      jobId: item.jobId
    }
    wx.navigateTo({
      url: '/pages/clockin/clockin?data=' + encodeURIComponent(JSON.stringify(data)),
    })

  },
  getDataList: function () {
    console.log(this.data.active)
    var str = "pageNo=" + this.data.pageNo + "&pageSize=10&statusList=1&statusList=4&statusList=3"
    // var str = "pageNo=" + this.data.pageNo + "&pageSize=10&statusList="+this.data.active
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getregistration1(str,
      function (res) {
        wx.hideLoading()
        console.log("------列表状态-0--", res);
        if (res.code == 0) {
          var pageNo = res.data.current;
          var total = res.data.pages;
          var arr = res.data.records;
          if (pageNo == 1) {
            that.setData({
              dataList: arr,
              pageNo,
              total
            })
          } else if (pageNo <= total) {

            that.setData({
              dataList: [...that.data.dataList, ...arr],
              pageNo,
              total
            })
          }
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDataList();
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  }
})